package com.woniu.humanresource.controller;

import com.woniu.humanresource.entity.CorporateBenefits;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.entity.Salary;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.CorporateBenefitsService;
import com.woniu.humanresource.service.SalarysService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//员工薪酬
@RestController
public class SalaryController {
    @Resource
    SalarysService salarysService;
    //分页查询企业福利
    @PostMapping("/salary/{pageIndex}/{pageSize}")
    public ResponseText getSalary(
            @PathVariable("pageIndex") int pageIndex,
            @PathVariable("pageSize") int pageSize,
            @RequestBody Salary salary){
        ResponseText<PageBean<Salary>> responseText=null;
        try {

            PageBean<Salary> pageBean = salarysService.selectSalary(salary, pageIndex, pageSize);
            responseText=new ResponseText<>(pageBean,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //添加企业福利
    @PostMapping("/addsalary")
    public ResponseText addSalary(@RequestBody Salary salary){
        ResponseText responseText=null;
        try {
            //待面试状态
           salarysService.insertSalary(salary);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //删除企业福利
    @DeleteMapping("/salary/{id}")
    public ResponseText deleteCorporateBenefits(@PathVariable("id") int id){
        ResponseText responseText=null;
        try {
            salarysService.deleteSalary(id);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //修改企业福利
    @PutMapping("/updatesalary")
    public ResponseText updateCorporateBenefits(@RequestBody Salary salary){
        ResponseText responseText=null;
        try {
           salarysService.updateSalary(salary);
            responseText=new ResponseText<PageBean<Salary>>(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

}
